// source --> http://msp.strengthandconditioningeducation.com/wp-content/plugins/wlm-for-infusionsoft/modules/subscription-update/js/subscriptionupdate-front.js?ver=1.0.144 jQuery(document).ready(function($) { //for subscriptions wlifcon_subscriptionupdate_vars.show_spinner = function( text ) { var spinner = 'Retrieving data...'; spinner = '

' +spinner +'
' +text +'

'; jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(spinner); } wlifcon_subscriptionupdate_vars.show_payments = function ( sub_id, nonce ) { var data = { action: "get_subscription_payments", nonce: nonce, subid: sub_id }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(response); jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').find('.wlifcon-subscription-invpayment').bind('click', wlifcon_subscriptionupdate_vars.subscription_invpayment_clicked ); jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').find('.wlifcon-print-invoice').bind('click', wlifcon_subscriptionupdate_vars.print_invoice_clicked ); }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.print_invoice_clicked = function ( e ) { child = window.open( jQuery(this).attr('href'), '', "height=800, width=700"); //Open the child in a tiny window. window.focus(); e.preventDefault(); } wlifcon_subscriptionupdate_vars.cancel_subscription = function ( ) { var holder = jQuery(this).parent().parent().parent().parent(); holder.find(".wlifcon-subscription-error-message").html(""); var reason = holder.find(".wlifcon-subscription-cancel-reason").val(); var subid = holder.find(".wlifcon-subscription-id").val(); var programid = holder.find(".wlifcon-subscription-programid").val(); var nonce = holder.find('.wlifcon-subscription-nonce').val(); var require_reason = holder.find(".wlifcon-subscription-req-reason").val(); if ( ! subid ) { alert("Invalid subscription. Please refresh the page and try again."); return; } if ( ! nonce ) { alert("Invalid request. Please refresh the page and try again."); return; } if ( require_reason == 1 && reason == "" ) { alert("Please fill up the reason filled to cancel this subscription."); return; } if ( ! confirm( 'You are about to cancel this subscription. Click “OK” to confirm.' ) ) { return; } wlifcon_subscriptionupdate_vars.show_spinner('Cancelling your subscription, please wait...'); var data = { action: "cancel_subscription", nonce: nonce, subid: subid, reason: reason }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { wlifcon_subscriptionupdate_vars.show_spinner( response ); location.reload(); }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.new_subscription = function ( pids, hash, nonce ) { var data = { action: "get_subscription_list", nonce: nonce, pids: pids, hash: hash }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(response); jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').find('.wlifcon-subscription-subscribe').bind('click', wlifcon_subscriptionupdate_vars.subscribe_subscription_clicked ); }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.update_subscription = function ( subid, programid, nonce, activetab ) { activetab = typeof activetab === 'undefined' ? 0 : activetab; var data = { action: "get_update_details", nonce: nonce, subid: subid, programid: programid }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(response); jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').find('.wlifcon-subscription-use-card').bind('click', wlifcon_subscriptionupdate_vars.subscription_change_card ); jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').find('.wlifcon-subscription-cancel').bind('click', wlifcon_subscriptionupdate_vars.cancel_subscription ); jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents .wlifcon-subscription-details-tabs').tabs({active: activetab}); }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.subscription_change_card = function ( ) { var holder = jQuery(this).parent().parent().parent().parent(); holder.find(".wlifcon-subscription-error-message").html(""); var ccid = holder.find(".wlifcon-subscription-ccid:checked").val(); var subid = holder.find(".wlifcon-subscription-id").val(); var programid = holder.find(".wlifcon-subscription-programid").val(); var nonce = holder.find('.wlifcon-subscription-nonce').val(); if ( ! ccid ) { alert("Please select a credit card to use."); return; } if ( ! subid ) { alert("Invalid subscription. Please refresh the page and try again."); return; } if ( ! nonce ) { alert("Invalid request. Please refresh the page and try again."); return; } wlifcon_subscriptionupdate_vars.show_spinner('Changing subscription\'s credit card, please wait...'); var data = { action: "update_subscription_cc", nonce: nonce, subid: subid, ccid: ccid }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { if ( response == "OK" ) { wlifcon_subscriptionupdate_vars.show_spinner("Subscription's credit card changed. Please wait..."); wlifcon_subscriptionupdate_vars.update_subscription( subid, programid, nonce, 1 ); } else { wlifcon_subscriptionupdate_vars.show_spinner( "" +response + " Please wait..."); wlifcon_subscriptionupdate_vars.update_subscription( subid, programid, nonce, 1 ); return; } }, error: function(){ wlifcon_subscriptionupdate_vars.show_spinner("An error occured while processing your request. Please wait..."); wlifcon_subscriptionupdate_vars.update_subscription( subid, programid, nonce, 1 ); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.subscription_invpayment = function ( invid, nonce ) { var modal = jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents'); var data = { action: "get_invpayment_details", nonce: nonce, invid: invid }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { modal.html(response); modal.find('.wlifcon-subscription-invpay').bind('click', wlifcon_subscriptionupdate_vars.subscription_invpay_clicked ); modal.find('.wlifcon-subscription-addcard').bind('click', wlifcon_subscriptionupdate_vars.subscription_addcard_clicked ); modal.find('.wlifcon-subscription-existingcard').bind('click', wlifcon_subscriptionupdate_vars.subscription_existingcard_clicked ); modal.find('.cc-useaddress').bind('click', wlifcon_subscriptionupdate_vars.subscription_useaddress_clicked ); }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.subscribe_subscription = function ( programid, nonce ) { var modal = jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents'); var data = { action: "get_subscription_details", nonce: nonce, programid: programid }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { modal.html(response); modal.find('.wlifcon-subscription-confirm').bind('click', wlifcon_subscriptionupdate_vars.confirm_subscription ); modal.find('.wlifcon-subscription-addcard').bind('click', wlifcon_subscriptionupdate_vars.subscription_addcard_clicked ); modal.find('.wlifcon-subscription-existingcard').bind('click', wlifcon_subscriptionupdate_vars.subscription_existingcard_clicked ); modal.find('.cc-useaddress').bind('click', wlifcon_subscriptionupdate_vars.subscription_useaddress_clicked ); }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.confirm_subscription = function ( ) { var holder = jQuery(this).parent().parent(); holder.find(".wlifcon-subscription-error-message").html(""); var ccid = holder.find(".wlifcon-subscription-ccid:checked").val(); var programid = holder.find(".wlifcon-subscription-programid").val(); var nonce = holder.find('.wlifcon-subscription-nonce').val(); var cardused = holder.find('.wlifcon-subscription-cardused').val(); var cc_name = holder.find('.cc_name').val(); var cc_type = holder.find('.cc_type option:selected').val(); var cc_number = holder.find('.cc_number').val(); var cc_expmonth = holder.find('.cc_expmonth option:selected').val(); var cc_expyear = holder.find('.cc_expyear option:selected').val(); var cc_cvv = holder.find('.cc_cvv').val(); var cc_useaddress = holder.find('.cc-useaddress').prop("checked"); var cc_streetaddress1 = holder.find('.cc_streetaddress1').val(); var cc_streetaddress2 = holder.find('.cc_streetaddress2').val(); var cc_city = holder.find('.cc_city').val(); var cc_state = holder.find('.cc_state').val(); var cc_postalcode = holder.find('.cc_postalcode').val(); var cc_country = holder.find('.cc_country option:selected').val(); if ( cardused == "new" ) { if ( ! cc_name || ! cc_type || ! cc_number || ! cc_expmonth || ! cc_expyear || ! cc_cvv ) { holder.find(".wlifcon-subscription-error-message").html("Please complete your credit card details."); return; } else if ( ! cc_useaddress ) { if ( ( ! cc_streetaddress1 && ! cc_streetaddress2 ) || ! cc_city || ! cc_state || ! cc_postalcode || ! cc_country ) { holder.find(".wlifcon-subscription-error-message").html("Please complete your address details."); return; } } } else { if ( ! ccid ) { holder.find(".wlifcon-subscription-error-message").html("Please select a credit card to use"); return; } } wlifcon_subscriptionupdate_vars.show_spinner("Processing your subscription, please wait..."); var data = { action : "confirm_subscription", nonce : nonce, programid : programid, ccid : ccid, cardused : cardused, cc_name : cc_name, cc_type : cc_type, cc_number : cc_number, cc_expmonth : cc_expmonth, cc_expyear : cc_expyear, cc_cvv : cc_cvv, cc_useaddress : cc_useaddress, cc_streetaddress1 : cc_streetaddress1, cc_streetaddress2 : cc_streetaddress2, cc_city : cc_city, cc_state : cc_state, cc_postalcode : cc_postalcode, cc_country : cc_country }; jQuery.ajax({ type: "POST", data: data, success: function( response ) { if ( response == "" ) { wlifcon_subscriptionupdate_vars.show_spinner("Your request has been processed, please wait..."); location.reload(); } else { wlifcon_subscriptionupdate_vars.show_spinner(response); wlifcon_subscriptionupdate_vars.subscribe_subscription( programid, nonce ); } }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.subscription_invpay_clicked = function () { var holder = jQuery(this).parent().parent(); holder.find(".wlifcon-subscription-error-message").html(""); var ccid = holder.find(".wlifcon-subscription-ccid:checked").val(); var invid = holder.find(".wlifcon-subscription-invid").val(); var nonce = holder.find('.wlifcon-subscription-nonce').val(); var cardused = holder.find('.wlifcon-subscription-cardused').val(); var cc_name = holder.find('.cc_name').val(); var cc_type = holder.find('.cc_type option:selected').val(); var cc_number = holder.find('.cc_number').val(); var cc_expmonth = holder.find('.cc_expmonth option:selected').val(); var cc_expyear = holder.find('.cc_expyear option:selected').val(); var cc_cvv = holder.find('.cc_cvv').val(); var cc_useaddress = holder.find('.cc-useaddress').prop("checked"); var cc_streetaddress1 = holder.find('.cc_streetaddress1').val(); var cc_streetaddress2 = holder.find('.cc_streetaddress2').val(); var cc_city = holder.find('.cc_city').val(); var cc_state = holder.find('.cc_state').val(); var cc_postalcode = holder.find('.cc_postalcode').val(); var cc_country = holder.find('.cc_country option:selected').val(); if ( cardused == "new" ) { if ( ! cc_name || ! cc_type || ! cc_number || ! cc_expmonth || ! cc_expyear || ! cc_cvv ) { holder.find(".wlifcon-subscription-error-message").html("Please complete your credit card details."); return; } else if ( ! cc_useaddress ) { if ( ( ! cc_streetaddress1 && ! cc_streetaddress2 ) || ! cc_city || ! cc_state || ! cc_postalcode || ! cc_country ) { holder.find(".wlifcon-subscription-error-message").html("Please complete your address details."); return; } } } else { if ( ! ccid ) { holder.find(".wlifcon-subscription-error-message").html("Please select a credit card to use"); return; } } var data = { action : "pay_invoice", nonce : nonce, invid : invid, ccid : ccid, cardused : cardused, cc_name : cc_name, cc_type : cc_type, cc_number : cc_number, cc_expmonth : cc_expmonth, cc_expyear : cc_expyear, cc_cvv : cc_cvv, cc_useaddress : cc_useaddress, cc_streetaddress1 : cc_streetaddress1, cc_streetaddress2 : cc_streetaddress2, cc_city : cc_city, cc_state : cc_state, cc_postalcode : cc_postalcode, cc_country : cc_country }; wlifcon_subscriptionupdate_vars.show_spinner("Processing your invoice payment, please wait..."); jQuery.ajax({ type: "POST", data: data, success: function( response ) { if ( response != "" ) { wlifcon_subscriptionupdate_vars.show_spinner(response); } else { wlifcon_subscriptionupdate_vars.show_spinner("Invoice successfully paid, please wait..."); } wlifcon_subscriptionupdate_vars.subscription_invpayment( invid, nonce ); }, error: function(){ alert('An error occured while processing your request, please refresh the page and try again.'); }, complete: function(){} }); } wlifcon_subscriptionupdate_vars.subscribe_subscription_clicked = function () { var main_holder = jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent(); var nonce = jQuery('.wlifcon-subscription-nonce').val(); var programid = jQuery(this).attr("programid"); if ( ! programid || ! nonce ) { alert('Invalid Request, please refresh the page and try again.'); return; } jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(); wlifcon_subscriptionupdate_vars.show_spinner('Preparing subscription details, please wait...'); main_holder.find('.wlifcon-subscription-modal').modal({ escClose:true, overlayClose: false, position: ["10%"], autoResize: true, minHeight: '70%', containerId: 'wlifcon-subscription-modal-holder', containerCss: { overflow:'auto'}, }); wlifcon_subscriptionupdate_vars.subscribe_subscription( programid, nonce ); } wlifcon_subscriptionupdate_vars.subscription_invpayment_clicked = function () { var main_holder = jQuery(this).parent().parent().parent().parent().parent().parent().parent().parent().parent(); var nonce = jQuery('.wlifcon-subscription-nonce').val(); var invid = jQuery(this).attr("invid"); if ( ! invid || ! nonce ) { alert('Invalid Request, please refresh the page and try again.'); return; } jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(); wlifcon_subscriptionupdate_vars.show_spinner('Preparing invoice payment form, please wait...'); main_holder.find('.wlifcon-subscription-modal').modal({ escClose:true, overlayClose: false, position: ["10%"], autoResize: true, minHeight: '70%', containerId: 'wlifcon-subscription-modal-holder', containerCss: { overflow:'auto'}, }); wlifcon_subscriptionupdate_vars.subscription_invpayment( invid, nonce ); } wlifcon_subscriptionupdate_vars.subscription_addcard_clicked = function () { var holder = jQuery(this).parent().parent(); holder.find('.credit-card-address').hide(); holder.find('.cc-useaddress').prop("checked",true); holder.find('.add-credit-card').show(); holder.find('.credit-card-list').hide(); holder.find('.wlifcon-subscription-existingcard').show(); holder.find('.wlifcon-subscription-addcard').hide(); holder.find('.wlifcon-subscription-cardused').val('new'); holder.find(".wlifcon-subscription-error-message").html(""); } wlifcon_subscriptionupdate_vars.subscription_existingcard_clicked = function () { var holder = jQuery(this).parent().parent(); holder.find('.credit-card-address').hide(); holder.find('.cc-useaddress').prop("checked",true); holder.find('.add-credit-card').hide(); holder.find('.credit-card-list').show(); holder.find('.wlifcon-subscription-existingcard').hide(); holder.find('.wlifcon-subscription-addcard').show(); holder.find('.wlifcon-subscription-cardused').val('existing'); holder.find(".wlifcon-subscription-error-message").html(""); } wlifcon_subscriptionupdate_vars.subscription_useaddress_clicked = function () { var holder = jQuery(this).parent().parent().parent().parent().parent().parent(); if ( jQuery(this).prop('checked') ){ holder.find('.credit-card-address').hide(); } else { holder.find('.credit-card-address').show(); } } jQuery('.wlifcon-subscription-modal-close a').on('click', function( e ) { e.preventDefault(); jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(""); jQuery.modal.close(); }); jQuery('.wlifcon-subscription-payments').on('click', function() { var main_holder = jQuery(this).parent().parent().parent().parent().parent(); var nonce = main_holder.find('.wlifcon-subscription-nonce').val(); var sub_id = jQuery(this).attr("subid"); if( ! sub_id ||!nonce ) { alert('Invalid Request, please refresh the page and try again.'); return; } jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(); wlifcon_subscriptionupdate_vars.show_spinner( 'Retrieving your subscription invoices, please wait...' ); main_holder.find('.wlifcon-subscription-modal').modal({ escClose:true, overlayClose: false, position: ["10%"], autoResize: true, minHeight: '80%', containerId: 'wlifcon-subscription-modal-holder', containerCss: { overflow:'auto'}, }); wlifcon_subscriptionupdate_vars.show_payments( sub_id, nonce , main_holder ); }); jQuery('.wlifcon-subscription-new').on('click', function() { var main_holder = jQuery(this).parent().parent(); var nonce = main_holder.find('.wlifcon-subscription-nonce').val(); var pids = jQuery(this).attr("pids"); var hash = jQuery(this).attr("hash"); if ( ! pids || ! nonce || ! hash ) { alert('Invalid Request, please refresh the page and try again.'); return; } jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(); wlifcon_subscriptionupdate_vars.show_spinner('Preparing subscription lists, please wait...'); main_holder.find('.wlifcon-subscription-modal').modal({ escClose:true, overlayClose: false, position: ["10%"], autoResize: true, minHeight: '70%', containerId: 'wlifcon-subscription-modal-holder', containerCss: { overflow:'auto'}, }); wlifcon_subscriptionupdate_vars.new_subscription( pids, hash, nonce ); }); jQuery('.wlifcon-subscription-update').on('click', function() { var main_holder = jQuery(this).parent().parent().parent().parent().parent(); var nonce = main_holder.find('.wlifcon-subscription-nonce').val(); var subid = jQuery(this).attr("subid"); var programid = jQuery(this).attr("programid"); if ( ! subid || ! nonce || ! programid ) { alert('Invalid Request, please refresh the page and try again.'); return; } jQuery('.wlifcon-subscription-modal .wlifcon-subscription-contents').html(); wlifcon_subscriptionupdate_vars.show_spinner('Preparing subscription details, please wait...'); main_holder.find('.wlifcon-subscription-modal').modal({ escClose:true, overlayClose: false, position: ["10%"], autoResize: true, minHeight: '70%', containerId: 'wlifcon-subscription-modal-holder', containerCss: { overflow:'auto'}, }); wlifcon_subscriptionupdate_vars.update_subscription( subid, programid, nonce ); }); });